//
//  HMStatusRetweetView.swift
//  CZBKWB31
//
//  Created by Linkon Y on 16/8/13.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
import SnapKit
//转发
class HMStatusRetweetView: UIView {
    //记录转发
    var RetweetViewConstraint: Constraint?
    
    var statusViewModel: HMStatusViewModel?{
        didSet{
            //转发微博正文
         contentLab.attributedText = statusViewModel?.retweetAttr
            //卸载约束
            RetweetViewConstraint?.uninstall()
            
            //有图片
            if statusViewModel?.statusModel?.retweeted_status?.pic_urls?.count > 0 {
                
                //赋值
                picView.picInfos = statusViewModel?.statusModel?.retweeted_status?.pic_urls
                
                self.snp_makeConstraints(closure: { (make) in
            RetweetViewConstraint = make.bottom.equalTo(picView.snp_bottom).offset(10).constraint
                    
                })
                picView.hidden = false
            }else{
            //无配图
                self.snp_makeConstraints(closure: { (make) in
                RetweetViewConstraint = make.bottom.equalTo(contentLab.snp_bottom).offset(10).constraint
                    
                })
                
                picView.hidden = true
            }
            
        }
    }

    override init(frame: CGRect) {
        super.init(frame:frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
   private func setupUI(){
         backgroundColor = RGB(237, green: 237, blue: 237)
    //增加控件
    addSubview(contentLab)
    addSubview(picView)
    
    //增加约束
    contentLab.snp_makeConstraints { (make) in
        make.leading.top.equalTo(self).offset(10)
    }
    picView.snp_makeConstraints { (make) in
        make.top.equalTo(contentLab.snp_bottom).offset(10)
        make.size.equalTo(CGSize(width: 100, height: 100))
        make.leading.equalTo((SCREENW - 250)/2)
        
    }
    self.snp_makeConstraints { (make) in
    RetweetViewConstraint = make.bottom.equalTo(picView.snp_bottom).offset(10).constraint
    }
    
   
    
    }
    //懒加载控件
    private lazy var contentLab = UILabel(textColor: UIColor.darkGrayColor(), textSize: 15, maxWidth: SCREENW - 20)
    //配图
    private lazy var picView :HMStatusPictureView = HMStatusPictureView()
    
}
